import cityCascader from "../../../component/cityCascader/index.vue";
export default {
  name: "dedicated",
  components: {
    tab: () => import("../../../component/tab/index.vue"),
    cityCascader
  },
  props:['totalNum'],
  data() {
    return {
      loading: false,
      btnAuthority: {},
      tabs: [{
          label: "待开票",
          status: "0"
        },
        {
          label: "已开票",
          status: "1"
        }
      ],
      form: {
        type: "1", // 专用发票
        status: "0", // 待开票
        starttime: "",
        endtime: "",
        companyname: "",
        province: '',
        city: '',
        area: '',
        pagenum: 1,
        pagesize: 10
      },
      total: 0,
      tableData: [],
      dialogVisible: false,
      invoiceDetail: {},
      provinceList: [],
      cityList: [],
      areaList: [],
      region: []
    };
  },
  created() {
    this.btnAuthority = this.GLOBAL.powerAllBtn.kpgl;
	console.log(this.GLOBAL)
    this.getTableData();
  },
  methods: {
    handleCityChange (val) {
      this.form.province = val[0];
      this.form.city = val[1];
      this.form.area = val[2];
    },
    // 时间比较
    compareDate() {
      let starttime = Date.parse(this.form.starttime);
      let endtime = Date.parse(this.form.endtime);
      if (starttime > endtime) {
        this.$message({
          message: '开始时间不能大于结束时间',
          type: 'error'
        });
        return false;
      } else {
        return true;
      }
    },
    getTableData() {
      if (!this.compareDate()) {
        return
      } else {
        this.loading = true;
        this.$axios.post("/app/v1/platform/invoice/applyList", this.form).then(res => {
          this.loading = false;
          if (res.data.code === 1) {
            this.tableData = res.data.data.list;
            this.total = +res.data.data.totalnum;
			if(this.form.status == 0){this.$emit('update:totalNum',res.data.data.totalnum)};
			console.log(res.data.data);
			console.log(this.form.status);
          } else {
            this.$message({
              message: res.data.message,
              type: "error"
            })
          }
        })
      }
    },
    query() {
      this.form.pagenum = 1;
      this.getTableData();
    },
    clickTab(item) {
      this.form.status = item.status;
      this.form.pagenum = 1;
      this.form.starttime = "",
      this.form.endtime = "",
      this.form.companyname = "",
      this.getTableData();
    },
    // 分页
    handleCurrentChange(val) {
      this.form.pagenum = val;
      this.getTableData();
    },
    handleSizeChange(val) {
      this.form.pagenum = 1;
      this.form.pagesize = val;
      this.getTableData();
    },
    // 详情
    viewDetails(invoiceid) {
      this.$axios.post("/app/v1/platform/invoice/applyDetail", {
        invoiceid
      }).then(res => {
        if (res.data.code === 1) {
          this.invoiceDetail = res.data.data;
          this.dialogVisible = true;
        } else {
          this.$message({
            message: res.data.message,
            type: "error"
          });
        }
      });
    },
    billing() {
      this.$axios.post("/app/v1/platform/invoice/applyResult", {
          invoiceid: this.invoiceDetail.invoiceid
        })
        .then(res => {
          if (res.data.message === "success.") {
            this.$message({
              message: "开票成功!",
              type: "success"
            });

          } else {
            this.$message({
              message: res.data.message,
              type: "error"
            });
          }
          this.dialogVisible = false;
          this.getTableData();
        });
    },
    closeDialog() {
      this.invoiceDetail = {};
    }
  }
};